package branch.snapshot;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author Alex
 *
 */
public class ChannelRecord implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5386965138331424748L;
	private final List<ITransfer> transferRecords;
	private final int localBranchId;
	private final int distantBranchId;
	
	public ChannelRecord(int localBranchId, int distantBranchId) {
		this.transferRecords = new ArrayList<ITransfer>();
		this.localBranchId = localBranchId;
		this.distantBranchId = distantBranchId;
	}
	
	public void record(ITransfer t){
		transferRecords.add(t);
	}
	
	public int getDistantBranchId(){
		return distantBranchId;
	}
	
	public int getTotalAmountTransfered(){
		int total = 0;
		for (ITransfer record: transferRecords){
			total += record.getAmount();
		}
		
		return total;
	}
	
	public String toString(){
		StringBuilder s = new StringBuilder();
		s.append(String.format("Channel S%d-S%d: %d$\n", localBranchId, distantBranchId, getTotalAmountTransfered()));
						
		return s.toString();
	}
}
